'use strict';

/**
 * @name 后台请求的resource
 * @description 向后台发请求的文件
 * @author Yud
 */
angular.module('metalabOperationApp').factory('MetaResources', ['$resource', function($resource) {
    var resources = {};

    var _config = CONFIG;

    var _host = _config.API_HOST;

    //网站搜索
    resources.search = $resource(_host, null, {
        'search': {
            url: _host + '/search/website_search',
            method: 'POST',
            isArray: true
        }
    });

    resources.xlsx = $resource(_host, null, {
        'get': {
            url: _host + '/:type/xlsx',
            method: 'GET'
        }
    });

    //信息的接口
    resources.message = $resource(_host, null, {
        'query': {
            url: _host + '/users/:user_id/messages',
            method: 'GET',
            isArray: true
        }
    });

    //用户的接口
    resources.user = $resource(_host, null, {
        'query': {
            url: _host + '/users',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/users/:id',
            method: 'GET',
            isArray: false
        },
        'save': {
            url: _host + '/users/:id',
            method: 'PUT'
        },
        'create': {
            url: _host + '/users',
            method: 'POST'
        },
        'getMoney': {
            url: _host + '/users/:user_id/account_records',
            method: 'GET',
            isArray: true
        },
        'getCollect': {
            url: _host + '/users/:user_id/favourites',
            method: 'GET',
            isArray: true
        },
        'saveMoney': {
            url: _host + '/account_records',
            method: 'POST'
        },
        'updatePassword': {
            url: _host + '/users/:id/update_password',
            method: 'PUT'
        },
        'updateRole': {
            url: _host + '/users/:id/update_role',
            method: 'PUT'
        }
    });

    //备注的接口
    resources.comment = $resource(_host, null, {
        'query': {
            url: _host + '/comments',
            method: 'GET',
            isArray: true
        },
        'save': {
            url: _host + '/users/:user_id/comments',
            method: 'POST'
        }
    });

    //评论的接口
    resources.note = $resource(_host, null, {
        'query': {
            url: _host + '/users/:user_id/solution_process_notes',
            method: 'GET',
            isArray: true
        },
        'save': {
            url: _host + '/users/:user_id/comments',
            method: 'POST'
        }
    });

    //需求resource接口
    resources.demand = $resource(_host, null, {
        'query': {
            url: _host + '/demands',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/demands/:id',
            method: 'GET',
            isArray: false
        },
        'save': {
            url: _host + '/demands/:id',
            method: 'PUT'
        },
        'post': {},
        'put': {},
        'delete': {},
        'queryNum': {
            url: _host + '/demands/:demand_id/solution_processes',
            method: 'GET',
            isArray: true
        },
        'download': {
            url: _host + '/demands/:id/download',
            method: 'GET'
        }
    });

    //技术方案的resource接口
    resources.technology = $resource(_host + '', null, {
        'query': {
            url: _host + '/technologies',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/technologies/:id',
            method: 'GET',
            isArray: false
        },
        'save': {
            url: _host + '/technologies/:id',
            method: 'PUT'
        },
        'post': {},
        'put': {},
        'delete': {},
        'queryNum': {
            url: _host + '/technologies/:technology_id/solution_processes',
            method: 'GET',
            isArray: true
        },
        'queryAreas': {
            url: _host + '/technologies/areas',
            method: 'GET'
        },
        'download': {
            url: _host + '/technologies/:id/download',
            method: 'GET'
        },
        'origins': {
            url: _host + '/technologies/origins',
            method: 'GET',
            isArray: true
        }
    });

    //进程的resource接口
    resources.process = $resource(_host + '', null, {
        'query': {
            url: _host + '/solution_processes',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/solution_processes/:id',
            method: 'GET',
            isArray: false
        },
        'save': {
            url: _host + '/solution_processes/:id',
            method: 'PUT'
        },
        'updateDemand': {
            url: _host + '/demand_side_processes/:id',
            method: 'PUT'
        },
        'updateTech': {
            url: _host + '/technology_side_processes/:id',
            method: 'PUT'
        }
    });

    //科研的resource接口
    resources.talent = $resource(_host + '', null, {
        'create': {
            url: _host + '/users/:id/talent',
            method: 'POST'
        },
        'query': {
            url: _host + '/talents',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/talents/:id',
            method: 'GET',
            isArray: false
        },
        'save': {
            url: _host + '/users/:id/talent',
            method: 'PUT'
        },
        'queryAreas': {
            url: _host + '/talents/:id/research_areas',
            method: 'GET',
            isArray: true
        },
        'createArea': {
            url: _host + '/talents/:id/research_areas',
            method: 'POST'
        },
        'saveArea': {
            url: _host + '/research_areas/:id',
            method: 'PUT'
        },
        'deleteArea': {
            url: _host + '/research_areas/:id',
            method: 'DELETE'
        },
        'queryAchievements': {
            url: _host + '/talents/:id/achievements',
            method: 'GET',
            isArray: true
        },
        'createAchievement': {
            url: _host + '/talents/:id/achievements',
            method: 'POST'
        },
        'saveAchievement': {
            url: _host + '/achievements/:id',
            method: 'PUT'
        },
        'deleteAchievement': {
            url: _host + '/achievements/:id',
            method: 'DELETE'
        }
    });

    //技术成果achievement接口
    resources.achievement = $resource(_host, null, {
        'get': {
            url: _host + '/research_spaces/:research_space_id/achievements',
            method: 'GET',
            isArray: true
        }
    });


    //技术资源的resource接口
    resources.researchSpace = $resource(_host + '', null, {
        'query': {
            url: _host + '/research_spaces',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/users/:user_id/research_space',
            method: 'GET',
            isArray: false
        },
        'post': {},
        'put': {},
        'delete': {}
    });

    //科研成果的resource接口
    resources.achievement = $resource(_host + '', null, {
        'query': {
            url: _host + '/research_spaces/:research_space_id/achievements',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/achievements/:id',
            method: 'GET',
            isArray: false
        },
        'post': {},
        'put': {},
        'delete': {}
    });

    //系统更新日志
    resources.update = $resource(_host + '', null, {
        'query': {
            url: _host + '/change_items',
            method: 'GET',
            isArray: true
        },
        'get': {
            url: _host + '/achievements/:id',
            method: 'GET',
            isArray: false
        },
        'create': {
            url: _host + '/change_items',
            method: 'POST'
        },
        'update': {
            url: _host + '/change_items/:id',
            method: 'PUT'
        },
        'delete': {
            url: _host + '/change_items/:id',
            method: 'DELETE'
        }
    });

    //有效性标签
    resources.tags = $resource(_host + '', null, {
        'demands': {
            url: _host + '/demands/effect_tags',
            method: 'GET',
            isArray: true
        },
        'technologies': {
            url: _host + '/technologies/effect_tags',
            method: 'GET',
            isArray: true
        }
    });

    resources.passport = $resource('', null, {
        'signIn': {
            url: _host + '/users/login',
            method: 'POST',
            isArray: false
        }
    });

    return resources;
}]);
